import {getOffset} from '@/utils'
export default {
  data () {
    return {
      fixed: false
    }
  },
  mounted () {
    window.addEventListener('scroll', this.handleScroll)
  },
  destroyed () {
    window.removeEventListener('scroll', this.handleScroll)
  },
  methods: {
    handleScroll () {
      const offset = getOffset(this.$el)
      const scrollTop = document.body.scrollTop || document.documentElement.scrollTop
      if (offset.y < scrollTop) {
        this.fixed = true
      } else {
        this.fixed = false
      }
    }
  }
}
